package hadoop.topN.question1;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class CourseJob1 {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Configuration conf=new Configuration();
        Job job = Job.getInstance(conf);
        job.setJarByClass(CourseJob1.class);
        job.setMapperClass(StuMapper1.class);
        job.setReducerClass(StuReducer1.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(DoubleWritable.class);
        job.setOutputKeyClass(CourseBean.class);
        job.setOutputValueClass(NullWritable.class);

        FileSystem fs = FileSystem.get(conf);
        Path path = new Path("D:\\apache-maven-3.6.3\\mavenRepository\\mapReduce\\output\\topN\\question1");
        if (fs.exists(path)){
            fs.delete(path,true);
        }
        FileInputFormat.setInputPaths(job,new Path("D:\\apache-maven-3.6.3\\mavenRepository\\mapReduce\\dataSet\\score.txt"));
        FileOutputFormat.setOutputPath(job,path);

        boolean isDone = job.waitForCompletion(true);
        System.exit(isDone ? 0 : 1);
    }
}
